package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.INX;
import emulator.hardware.nmos6502.operands.NoOperand;

public class INXTest {

	@Test
	public void testIncPositive() throws EmulatorException {
		executeAndCheckINX(0x3F, 0);
	}

	@Test
	public void testIncNegative() throws EmulatorException {
		executeAndCheckINX(0x7F, Flags6502.FLAG_NEGATIVE);
	}

	@Test
	public void testIncZero() throws EmulatorException {
		executeAndCheckINX(0xFF, Flags6502.FLAG_ZERO);
	}

	private void executeAndCheckINX(int x_val, int expected_flags)
			throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		cpu.setX(new HwByte(x_val));
		new INX().execute(cpu, new NoOperand());
		assertEquals(new HwByte(x_val+1), cpu.getX());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}

}
